/**
 * 对象池
 */
export default class {
    constructor() {
        this._recyclingPool = [];
    }
    /**
     * 创建
     * @returns {*}
     */
    create({ creater = () => {}, matcher = () => true }) {
        const index = this._recyclingPool.findIndex(matcher);
        if (index === -1) {
            return creater();
        } else {
            return this._recyclingPool.splice(index, 1)[0];
        }
    }
    /**
     * 回收
     * @returns {*}
     */
    recovery(...args) {
        this._recyclingPool.push(...args);
    }
    /**
     * 清空对象池
     * @returns {*}
     */
    clear(remover = () => {}) {
        this._recyclingPool.forEach(remover);
        this._recyclingPool = [];
    }
}
